package com.weixing.mall.provider.controller.front;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.AuthUtil;
import com.weixing.mall.core.support.auth.MemAuth;
import com.weixing.mall.provider.model.dto.ExchangeGoodsPointDto;
import com.weixing.mall.provider.model.query.OrderPointQuery;
import com.weixing.mall.provider.model.vo.OrderPointVo;
import com.weixing.mall.provider.service.IOrderPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 积分接口
 */
@RestController
@RequestMapping(value = "/front/orderPoint")
public class FrontOrderPointController extends BaseController {
    @Autowired
    private IOrderPointService orderPointService;
    /**
     * 兑换积分商品
     *
     * @param  dto  参数
     */
    @PostMapping(value = "exchange")
    @NoRepeatSubmit(leaseTime = 20)
    public Result exchangeGoodsPoint(@RequestBody ExchangeGoodsPointDto dto){
        MemAuth memAuth = AuthUtil.getMemberExt();
        return orderPointService.exchangeGoodsPoint(dto,memAuth.getMid());
    }

    /**
     * 兑换积分商品列表
     *
     * @return 积分商品列表
     */
    @GetMapping("list")
    public Result<IPage<OrderPointVo>> selectOrderPointList(){
        MemAuth memAuth = AuthUtil.getMemberExt();
        return ResultUtil.success(orderPointService.selectOrderPointList(initMpPage(),new OrderPointQuery(),memAuth.getMid()));
    }
}
